﻿Imports DotNetNuke
Imports DotNetNuke.Entities.Modules

Partial Class ControlPanel
    Inherits PortalModuleBase
    Implements IActionable

    Private Sub BindFeatureGroups_Grid()

        CType(gvFeatureGroups.Columns(2), ButtonField).Text = Services.Localization.Localization.GetString("Up.Text", Me.LocalResourceFile)
        CType(gvFeatureGroups.Columns(3), ButtonField).Text = Services.Localization.Localization.GetString("Down.Text", Me.LocalResourceFile)
        CType(gvFeatureGroups.Columns(4), CommandField).EditText = Services.Localization.Localization.GetString("Edit.Text", Me.LocalResourceFile)
        CType(gvFeatureGroups.Columns(4), CommandField).CancelText = Services.Localization.Localization.GetString("Cancel.Text", Me.LocalResourceFile)
        CType(gvFeatureGroups.Columns(4), CommandField).UpdateText = Services.Localization.Localization.GetString("Update.Text", Me.LocalResourceFile)
        CType(gvFeatureGroups.Columns(5), CommandField).DeleteText = Services.Localization.Localization.GetString("Delete.Text", Me.LocalResourceFile)

        Me.gvFeatureGroups.DataSource = New FeatureGroupController().GetFeatureGroupsByProductGroupId(CInt(Me.ddlFGPG.SelectedValue))
        Me.gvFeatureGroups.DataBind()
        If (Me.gvFeatureGroups.Rows.Count <= 0) Then
            Me.gvFeatureGroups.Visible = False
            Me.lblFeatureGroup.Visible = True
        Else
            Me.gvFeatureGroups.Visible = True
            Me.lblFeatureGroup.Visible = False
        End If
    End Sub

    Private Sub BindFeatures_Grid()

        CType(gvFeatures.Columns(2), ButtonField).Text = Services.Localization.Localization.GetString("Up.Text", Me.LocalResourceFile)
        CType(gvFeatures.Columns(3), ButtonField).Text = Services.Localization.Localization.GetString("Down.Text", Me.LocalResourceFile)
        CType(gvFeatures.Columns(4), CommandField).EditText = Services.Localization.Localization.GetString("Edit.Text", Me.LocalResourceFile)
        CType(gvFeatures.Columns(4), CommandField).CancelText = Services.Localization.Localization.GetString("Cancel.Text", Me.LocalResourceFile)
        CType(gvFeatures.Columns(4), CommandField).UpdateText = Services.Localization.Localization.GetString("Update.Text", Me.LocalResourceFile)
        CType(gvFeatures.Columns(5), CommandField).DeleteText = Services.Localization.Localization.GetString("Delete.Text", Me.LocalResourceFile)

        Me.gvFeatures.DataSource = New FeatureController().GetFeatures(CInt(Me.ddlFFG.SelectedValue))
        Me.gvFeatures.DataBind()
        If (Me.gvFeatures.Rows.Count <= 0) Then
            Me.gvFeatures.Visible = False
            Me.lblFeatures.Visible = True
            Me.lblFeatures.Text = Services.Localization.Localization.GetString("NoFeatures.Text", Me.LocalResourceFile)
        Else
            Me.ddlFFG.Enabled = True
            Me.gvFeatures.Visible = True
            Me.lblFeatures.Visible = False
        End If
        Me.lkbAddFeature.Enabled = True
    End Sub

    Private Sub BindProductGroups_DDL()
        Me.ddlProductGroups.DataSource = New ProductGroupController().GetProductGroupsByModuleId(Me.ModuleId)
        Me.ddlProductGroups.DataValueField = "ProductGroupId"
        Me.ddlProductGroups.DataTextField = "ProductGroup"
        Me.ddlProductGroups.DataBind()
        If (Not Me.Session.Item("ProductGroupId") Is Nothing) Then
            Me.ddlProductGroups.SelectedValue = Convert.ToString(CInt(Me.Session.Item("ProductGroupId")))
        End If
        If (Me.ddlProductGroups.Items.Count <= 0) Then
            Me.Session.Item("ProductGroupId") = Nothing
            Me.ddlProductGroups.Items.Insert(0, Services.Localization.Localization.GetString("None.Text", Me.LocalResourceFile))
            Me.ddlProductGroups.Items.Item(0).Value = "0"
            Me.ddlProductGroups.Enabled = False
            Me.gvProducts.Visible = False
            Me.lblProductGroup.Visible = True
            Me.lblProductGroup.Text = Services.Localization.Localization.GetString("NoPGs.Text", Me.LocalResourceFile)
        Else
            Me.ddlProductGroups.Enabled = True
            Me.gvProducts.Visible = True
            Me.lblProductGroup.Visible = False
        End If
    End Sub

    Private Sub BindPFTGrid()
        Try
            CType(gvPFT.Columns(4), CommandField).EditText = Services.Localization.Localization.GetString("Edit.Text", Me.LocalResourceFile)
            CType(gvPFT.Columns(4), CommandField).CancelText = Services.Localization.Localization.GetString("Cancel.Text", Me.LocalResourceFile)
            CType(gvPFT.Columns(4), CommandField).UpdateText = Services.Localization.Localization.GetString("Update.Text", Me.LocalResourceFile)
            CType(gvPFT.Columns(5), CommandField).DeleteText = Services.Localization.Localization.GetString("Delete.Text", Me.LocalResourceFile)

            Me.gvPFT.DataSource = New ProductController().GetProductAndFeaturesWithNotes(CInt(Me.ddlPFTFGs.SelectedValue))
            Me.gvPFT.DataBind()
        Catch ex As Exception
            Me.gvPFT.Visible = False
            Me.lblPFTMessage.Visible = True
            Exit Sub
        End Try

        If Me.gvPFT.Rows.Count <= 0 Then
            Me.gvPFT.Visible = False
            Me.lblPFTMessage.Visible = True
        Else
            Me.gvPFT.Visible = True
            Me.lblPFTMessage.Visible = False
        End If
    End Sub

    Private Sub BindPFTPanel()
        Me.ddlPFTPGs.DataSource = New ProductGroupController().GetProductGroupsByModuleId(Me.ModuleId)
        Me.ddlPFTPGs.DataValueField = "ProductGroupId"
        Me.ddlPFTPGs.DataTextField = "ProductGroup"
        Me.ddlPFTPGs.DataBind()
        Me.ddlPFTPGs.Enabled = True


        If (Me.ddlPFTPGs.Items.Count <= 0) Then
            Me.ddlPFTPGs.Items.Insert(0, Services.Localization.Localization.GetString("None.Text", Me.LocalResourceFile))
            Me.ddlPFTPGs.Items.Item(0).Value = "0"
            Me.ddlPFTPGs.Enabled = False

            Me.ddlPFTFGs.Items.Insert(0, Services.Localization.Localization.GetString("None.Text", Me.LocalResourceFile))
            Me.ddlPFTFGs.Items.Item(0).Value = "0"
            Me.ddlPFTFGs.Enabled = False

            Me.gvPFT.Visible = False
            Me.lblPFTMessage.Visible = True
            Me.lkbAddPFText.Enabled = False
            Me.lblPFTMessage.Text = Services.Localization.Localization.GetString("NoPGs.Text", Me.LocalResourceFile)
        Else
            Me.ddlPFTFGs.DataSource = New FeatureGroupController().GetFeatureGroupsByProductGroupId(CInt(ddlPFTPGs.SelectedValue))
            Me.ddlPFTFGs.DataValueField = "FeatureGroupId"
            Me.ddlPFTFGs.DataTextField = "FeatureGroup"
            Me.ddlPFTFGs.DataBind()
            Me.ddlPFTFGs.Enabled = True

            If (Me.ddlPFTFGs.Items.Count <= 0) Then
                Me.ddlPFTFGs.Items.Insert(0, Services.Localization.Localization.GetString("None.Text", Me.LocalResourceFile))
                Me.ddlPFTFGs.Items.Item(0).Value = "0"
                Me.ddlPFTFGs.Enabled = False
                Me.gvPFT.Visible = False
                Me.lkbAddPFText.Enabled = False
                Me.lblPFTMessage.Visible = True
                Me.lblPFTMessage.Text = Services.Localization.Localization.GetString("NoFGs.Text", Me.LocalResourceFile)
            Else
                Me.lkbAddPFText.Visible = True
                Me.gvPFT.EditIndex = -1
                BindPFTGrid()
            End If
            'Me.ddlPFTPGs.Enabled = True
            'Me.gvPFT.Visible = True
            'Me.lblPFTMessage.Visible = False
        End If
    End Sub

    Private Sub BindProductGroups_Grid()

        CType(gvProductGroups.Columns(1), CommandField).EditText = Services.Localization.Localization.GetString("Edit.Text", Me.LocalResourceFile)
        CType(gvProductGroups.Columns(1), CommandField).CancelText = Services.Localization.Localization.GetString("Cancel.Text", Me.LocalResourceFile)
        CType(gvProductGroups.Columns(1), CommandField).UpdateText = Services.Localization.Localization.GetString("Update.Text", Me.LocalResourceFile)
        CType(gvProductGroups.Columns(2), CommandField).DeleteText = Services.Localization.Localization.GetString("Delete.Text", Me.LocalResourceFile)
        
        Me.gvProductGroups.DataSource = New ProductGroupController().GetProductGroupsByModuleId(Me.ModuleId)
        Me.gvProductGroups.DataBind()
        If (Me.gvProductGroups.Rows.Count <= 0) Then
            Me.gvProductGroups.Visible = False
            Me.lblProductGroup.Visible = True
        Else
            Me.gvProductGroups.Visible = True
            Me.lblProductGroup.Visible = False
        End If
    End Sub

    Private Sub BindProducts_Grid()

        CType(gvProducts.Columns(3), ButtonField).Text = Services.Localization.Localization.GetString("Up.Text", Me.LocalResourceFile)
        CType(gvProducts.Columns(4), ButtonField).Text = Services.Localization.Localization.GetString("Down.Text", Me.LocalResourceFile)
        CType(gvProducts.Columns(5), CommandField).EditText = Services.Localization.Localization.GetString("Edit.Text", Me.LocalResourceFile)
        CType(gvProducts.Columns(5), CommandField).CancelText = Services.Localization.Localization.GetString("Cancel.Text", Me.LocalResourceFile)
        CType(gvProducts.Columns(5), CommandField).UpdateText = Services.Localization.Localization.GetString("Update.Text", Me.LocalResourceFile)
        CType(gvProducts.Columns(6), CommandField).DeleteText = Services.Localization.Localization.GetString("Delete.Text", Me.LocalResourceFile)

        Me.gvProducts.DataSource = New ProductController().GetProductListByProductGroupId(CInt(Me.ddlProductGroups.SelectedValue))
        Me.gvProducts.DataBind()
        If (Me.gvProducts.Rows.Count <= 0) Then
            Me.gvProducts.Visible = False
            Me.lblProduct.Visible = True
            Me.lblProduct.Text = Services.Localization.Localization.GetString("NoProducts.Text", Me.LocalResourceFile)
        Else
            Me.ddlProductGroups.Enabled = True
            Me.gvProducts.Visible = True
            Me.lblProduct.Visible = False
        End If
    End Sub

    Private Sub ddlFFG_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlFFG.SelectedIndexChanged
        Me.pnlFeatures.Visible = True
        Me.pnlSaveFeature.Visible = False
        Me.BindFeatures_Grid()
    End Sub

    Private Sub ddlFGPG_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlFGPG.SelectedIndexChanged
        Me.BindFeatureGroups_Grid()
    End Sub

    Private Sub ddlFPG_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlFPG.SelectedIndexChanged
        Me.pnlFeatures.Visible = True
        Me.pnlSaveFeature.Visible = False
        Me.ddlFFG.DataSource = New FeatureGroupController().GetFeatureGroupsByProductGroupId(CInt(Me.ddlFPG.SelectedValue))
        Me.ddlFFG.DataTextField = "FeatureGroup"
        Me.ddlFFG.DataValueField = "FeatureGroupId"
        Me.ddlFFG.DataBind()
        If (Me.ddlFFG.Items.Count > 0) Then
            Me.lkbAddFeature.Enabled = True
            Me.BindFeatures_Grid()
        Else
            Me.ddlFFG.Items.Clear()
            Me.ddlFFG.Items.Insert(0, Services.Localization.Localization.GetString("None.Text", Me.LocalResourceFile))
            Me.ddlFFG.Enabled = False
            Me.lkbAddFeature.Enabled = False
            Me.gvFeatures.Visible = False
            Me.lblFeatures.Text = Services.Localization.Localization.GetString("NoFGs.Text", Me.LocalResourceFile)
            Me.lblFeatures.Visible = True
        End If
    End Sub

    Private Sub ddlProductGroups_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlProductGroups.SelectedIndexChanged
        Me.BindProducts_Grid()
    End Sub

    Private Sub gvFeatureGroups_RowCancelingEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs) Handles gvFeatureGroups.RowCancelingEdit
        Me.gvFeatureGroups.EditIndex = -1
        Me.gvFeatureGroups.Columns.Item(4).ItemStyle.Width = 15
        Me.BindFeatureGroups_Grid()
        Me.rfvFG.Enabled = True
        Me.lkbAddFG.Enabled = True
    End Sub

    Private Sub gvFeatureGroups_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gvFeatureGroups.RowCommand
        _FeatureGroupSortOrder = (CInt(e.CommandArgument) + 1)
        If e.CommandName.Equals("UP") And CInt(e.CommandArgument) > 0 Then
            Dim fgc As New FeatureGroupController()
            fgc.SaveFeatureGroupSortOrder(CInt(Me.gvFeatureGroups.DataKeys.Item(CInt(e.CommandArgument)).Value), (_FeatureGroupSortOrder - 1), _FeatureGroupSortOrder)
            Me.gvProducts.EditIndex = -1
            Me.BindFeatureGroups_Grid()
        ElseIf e.CommandName.Equals("DOWN") And CInt(e.CommandArgument) < (Me.gvFeatureGroups.Rows.Count - 1) Then
            Dim fgc As New FeatureGroupController()
            fgc.SaveFeatureGroupSortOrder(CInt(gvFeatureGroups.DataKeys.Item(CInt(e.CommandArgument)).Value), (_FeatureGroupSortOrder + 1), _FeatureGroupSortOrder)
            gvProducts.EditIndex = -1
            BindFeatureGroups_Grid()
        End If
    End Sub

    Private Sub gvFeatureGroups_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs) Handles gvFeatureGroups.RowDeleting
        Dim fgc As New FeatureGroupController()
        fgc.DeleteFeatureGroup(CInt(Me.gvFeatureGroups.DataKeys.Item(e.RowIndex).Value))
        Me.gvFeatureGroups.EditIndex = -1
        Me.BindFeatureGroups_Grid()
    End Sub

    Private Sub gvFeatureGroups_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs) Handles gvFeatureGroups.RowEditing
        Me.rfvFG.Enabled = False
        Me.lkbAddFG.Enabled = False
        Me.gvFeatureGroups.EditIndex = e.NewEditIndex
        Me.gvFeatureGroups.Columns.Item(4).ItemStyle.Width = 40
        Me.BindFeatureGroups_Grid()
    End Sub

    Private Sub gvFeatureGroups_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles gvFeatureGroups.RowUpdating
        Dim fg As New FeatureGroupInfo
        Dim controller As New FeatureGroupController
        Me.rfvFG.Enabled = True
        Me.lkbAddFG.Enabled = True
        fg.FeatureGroup = Strings.Trim(CType(Me.gvFeatureGroups.Rows.Item(e.RowIndex).Cells.Item(0).Controls.Item(0), TextBox).Text)
        fg.FeatureGroupId = CInt(Me.gvFeatureGroups.DataKeys.Item(e.RowIndex).Value)
        fg.PortalId = Me.PortalId
        fg.ProductGroupId = CInt(Me.ddlFGPG.SelectedValue)
        fg.SortOrder = Me._FeatureGroupSortOrder
        controller.SaveFeatureGroup(fg)
        Me.gvFeatureGroups.EditIndex = -1
        Me.gvFeatureGroups.Columns.Item(4).ItemStyle.Width = 15
        Me.BindFeatureGroups_Grid()
    End Sub

    Private Sub gvFeatures_RowCancelingEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs) Handles gvFeatures.RowCancelingEdit
        Me.gvFeatures.EditIndex = -1
        Me.BindFeatures_Grid()
    End Sub

    Private Sub gvFeatures_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gvFeatures.RowCommand
        _FeatureSortOrder = (CInt(e.CommandArgument) + 1)
        If e.CommandName.Equals("UP") And CInt(e.CommandArgument) > 0 Then
            Dim fc As New FeatureController()
            fc.SaveFeatureSortOrder(CInt(Me.gvFeatures.DataKeys.Item(CInt(e.CommandArgument)).Value), (_FeatureSortOrder - 1), _FeatureSortOrder)
            Me.gvFeatures.EditIndex = -1
            Me.BindFeatures_Grid()
        ElseIf e.CommandName.Equals("DOWN") And CInt(e.CommandArgument) < (Me.gvFeatures.Rows.Count - 1) Then
            Dim fc As New FeatureController()
            fc.SaveFeatureSortOrder(CInt(Me.gvFeatures.DataKeys.Item(CInt(e.CommandArgument)).Value), (_FeatureSortOrder + 1), _FeatureSortOrder)
            Me.gvFeatures.EditIndex = -1
            Me.BindFeatures_Grid()
        End If
    End Sub

    Private Sub gvFeatures_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs) Handles gvFeatures.RowDeleting
        Dim fc As New FeatureController()
        fc.DeleteFeature(CInt(Me.gvFeatures.DataKeys.Item(e.RowIndex).Value))
        Me.gvFeatures.EditIndex = -1
        Me.BindFeatures_Grid()
    End Sub

    Private Sub gvFeatures_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs) Handles gvFeatures.RowEditing
        Me.gvFeatures.EditIndex = e.NewEditIndex
        Me.lblFeatures.Visible = False
        Me.gvFeatures.Visible = False
        Me.pnlSaveFeature.Visible = True
        Dim feature As New FeatureInfo
        feature = New FeatureController().GetFeature(CInt(Me.gvFeatures.DataKeys.Item(e.NewEditIndex).Value))
        Me.txtComment.Text = feature.Comment
        Me.txtFeature.Text = feature.Feature
        Me.ddlFFG.SelectedValue = feature.FeatureGroupId.ToString
        Me.Session.Item("apc_FeatureId") = feature.FeatureId
        Me.gvFeatures.EditIndex = -1
        Me.lkbAddFeature.Enabled = False
    End Sub

    Private Sub gvProductGroups_RowCancelingEdit(ByVal source As Object, ByVal e As GridViewCancelEditEventArgs) Handles gvProductGroups.RowCancelingEdit
        Me.gvProductGroups.EditIndex = -1
        Me.gvProductGroups.Columns.Item(1).ItemStyle.Width = 15
        Me.rfvPG.Enabled = True
        Me.lkbSaveProductGroup.Enabled = True
        Me.BindProductGroups_Grid()
    End Sub

    Private Sub gvProductGroups_RowDeleting(ByVal source As Object, ByVal e As GridViewDeleteEventArgs) Handles gvProductGroups.RowDeleting
        Dim pgc As New ProductGroupController()
        Dim text As String = Convert.ToString(Me.Settings.Item("ProductGroupId"))
        If CInt(Me.gvProductGroups.DataKeys.Item(e.RowIndex).Value) = CInt(Me.Settings.Item("ProductGroupId")) Then
            Dim mc As New ModuleController()
            mc.DeleteModuleSetting(Me.ModuleId, "ProductGroupId")
            mc = Nothing
        End If
        pgc.DeleteProductGroup(CInt(Me.gvProductGroups.DataKeys.Item(e.RowIndex).Value))
        Me.gvProductGroups.EditIndex = -1
        Me.BindProductGroups_Grid()
    End Sub

    Private Sub gvProductGroups_RowEditing(ByVal source As Object, ByVal e As GridViewEditEventArgs) Handles gvProductGroups.RowEditing
        Me.gvProductGroups.EditIndex = e.NewEditIndex
        Me.gvProductGroups.Columns.Item(1).ItemStyle.Width = 40
        Me.rfvPG.Enabled = False
        Me.lkbSaveProductGroup.Enabled = False
        Me.BindProductGroups_Grid()
    End Sub

    Private Sub gvProductGroups_RowUpdating(ByVal source As Object, ByVal e As GridViewUpdateEventArgs) Handles gvProductGroups.RowUpdating
        Dim box As TextBox = CType(Me.gvProductGroups.Rows.Item(e.RowIndex).Cells.Item(0).Controls.Item(0), TextBox)
        Dim pg As New ProductGroupInfo
        Dim controller As New ProductGroupController
        pg.PortalId = Me.PortalId
        pg.ModuleId = Me.ModuleId
        pg.ProductGroup = Strings.Trim(box.Text)
        pg.ProductGroupId = CInt(Me.gvProductGroups.DataKeys.Item(e.RowIndex).Value)
        controller.SaveProductGroup(pg)
        Me.gvProductGroups.EditIndex = -1
        Me.gvProductGroups.Columns.Item(1).ItemStyle.Width = 15
        Me.rfvPG.Enabled = True
        Me.lkbSaveProductGroup.Enabled = True
        Me.BindProductGroups_Grid()
    End Sub

    Private Sub gvProducts_RowCancelingEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs) Handles gvProducts.RowCancelingEdit
        Me.gvProducts.EditIndex = -1
        Me.gvProducts.Columns.Item(5).ItemStyle.Width = 15
        Me.BindProducts_Grid()
    End Sub

    Private Sub gvProducts_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gvProducts.RowCommand
        _ProductSortOrder = (CInt(e.CommandArgument) + 1)
        If e.CommandName.Equals("UP") And CInt(e.CommandArgument) > 0 Then
            Dim pc As New ProductController
            pc.SaveProductSortOrder(CInt(Me.gvProducts.DataKeys.Item(CInt(e.CommandArgument)).Value), (Me._ProductSortOrder - 1), Me._ProductSortOrder)
            Me.gvProducts.EditIndex = -1
            Me.BindProducts_Grid()
        ElseIf e.CommandName.Equals("DOWN") And CInt(e.CommandArgument) < (Me.gvProducts.Rows.Count - 1) Then
            Dim pc As New ProductController
            pc.SaveProductSortOrder(CInt(Me.gvProducts.DataKeys.Item(CInt(e.CommandArgument)).Value), (Me._ProductSortOrder + 1), Me._ProductSortOrder)
            Me.gvProducts.EditIndex = -1
            Me.BindProducts_Grid()
        End If
    End Sub

    Private Sub gvProducts_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs) Handles gvProducts.RowDeleting
        Dim pc As New ProductController
        pc.DeleteProduct(CInt(Me.gvProducts.DataKeys.Item(e.RowIndex).Value))
        Me.gvProducts.EditIndex = -1
        Me.BindProducts_Grid()
    End Sub

    Private Sub gvProducts_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs) Handles gvProducts.RowEditing
        Me.gvProducts.EditIndex = e.NewEditIndex
        Me.lblProduct.Visible = False
        Me.gvProducts.Visible = False
        Me.pnlSaveProduct.Visible = True
        Dim product As New ProductInfo
        product = New ProductController().GetProduct(CInt(Me.gvProducts.DataKeys.Item(e.NewEditIndex).Value))
        Me.txtProduct.Text = product.Product
        Me.txtPrice.Text = product.Price.ToString("F")
        Me.chbShowPrice.Checked = product.DisplayPrice
        If Not product.DisplayPrice Then
            Me.txtPrice.Enabled = False
        End If
        Me.Session.Item("apc_ProductId") = product.ProductId
        Me.gvProducts.EditIndex = -1
        Me.lkbAddProduct.Enabled = False
    End Sub

    Private Sub gvProducts_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles gvProducts.RowUpdating
        Dim prod As New ProductInfo
        Dim controller As New ProductController
        prod.ProductId = CInt(Me.gvProducts.DataKeys.Item(e.RowIndex).Value)
        prod.Price = CDec(CType(Me.gvProducts.Rows.Item(e.RowIndex).Cells.Item(1).Controls.Item(0), TextBox).Text)
        prod.Product = Trim(CType(Me.gvProducts.Rows.Item(e.RowIndex).Cells.Item(0).Controls.Item(0), TextBox).Text)
        prod.ProductGroupId = CInt(Me.ddlProductGroups.SelectedValue)
        prod.SortOrder = Me._ProductSortOrder
        controller.SaveProduct(prod)
        Me.gvProducts.EditIndex = -1
        Me.gvProducts.Columns.Item(5).ItemStyle.Width = 15
        Me.BindProducts_Grid()
    End Sub

    Private Sub lbFeatureGroups_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lbFeatureGroups.Click
        Me.pnlProductFeatureText.Visible = False
        Me.pnlFeatureGroups.Visible = True
        Me.pnlProductGroups.Visible = False
        Me.pnlProducts.Visible = False
        Me.pnlFeatures.Visible = False
        Me.txtFeatureGroup.Text = String.Empty
        Me.ddlFGPG.DataSource = New ProductGroupController().GetProductGroupsByModuleId(Me.ModuleId)
        Me.ddlFGPG.DataValueField = "ProductGroupId"
        Me.ddlFGPG.DataTextField = "ProductGroup"
        Me.ddlFGPG.DataBind()
        If (Me.ddlFGPG.Items.Count <= 0) Then
            Me.ddlFGPG.Items.Insert(0, Services.Localization.Localization.GetString("None.Text", Me.LocalResourceFile))
            Me.ddlFGPG.Items.Item(0).Value = "0"
            Me.ddlFGPG.Enabled = False
            Me.gvFeatureGroups.Visible = False
            Me.lblFeatureGroup.Visible = True
            Me.lkbAddFG.Enabled = False
            Me.lblFeatureGroup.Text = Services.Localization.Localization.GetString("NoPGsForFGs.Text", Me.LocalResourceFile)
        Else
            Me.gvFeatureGroups.EditIndex = -1
            Me.BindFeatureGroups_Grid()
            Me.rfvFG.Enabled = True
            Me.lkbAddFG.Enabled = True
        End If
    End Sub

    Private Sub lbFeatures_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lbFeatures.Click
        Me.pnlProductFeatureText.Visible = False
        Me.pnlFeatures.Visible = True
        Me.pnlProductGroups.Visible = False
        Me.pnlFeatureGroups.Visible = False
        Me.pnlProducts.Visible = False
        Me.pnlFeatures.Visible = True
        Me.pnlSaveFeature.Visible = False
        Me.txtComment.Text = String.Empty
        Me.txtFeature.Text = String.Empty
        Me.lkbAddFeature.Enabled = True
        Me.ddlFPG.DataSource = New ProductGroupController().GetProductGroupsByModuleId(Me.ModuleId)
        Me.ddlFPG.DataValueField = "ProductGroupId"
        Me.ddlFPG.DataTextField = "ProductGroup"
        Me.ddlFPG.DataBind()
        If (Me.ddlFPG.Items.Count <= 0) Then
            Me.ddlFPG.Items.Insert(0, Services.Localization.Localization.GetString("None.Text", Me.LocalResourceFile))
            Me.ddlFPG.Items.Item(0).Value = "0"
            Me.ddlFPG.Enabled = False
            Me.ddlFFG.Items.Insert(0, Services.Localization.Localization.GetString("None.Text", Me.LocalResourceFile))
            Me.ddlFFG.Items.Item(0).Value = "0"
            Me.ddlFFG.Enabled = False
            Me.gvFeatures.Visible = False
            Me.lblFeatures.Visible = True
            Me.lkbAddFeature.Enabled = False
            Me.lblFeatures.Text = Services.Localization.Localization.GetString("NoPGsForFeatures.Text", Me.LocalResourceFile)
        Else
            Me.ddlFFG.DataSource = New FeatureGroupController().GetFeatureGroupsByProductGroupId(CInt(Me.ddlFPG.SelectedValue))
            Me.ddlFFG.DataTextField = "FeatureGroup"
            Me.ddlFFG.DataValueField = "FeatureGroupId"
            Me.ddlFFG.DataBind()
            If (Me.ddlFFG.Items.Count > 0) Then
                Me.lkbAddFeature.Enabled = True
                Me.BindFeatures_Grid()
            Else
                Me.ddlFFG.Items.Clear()
                Me.ddlFFG.Items.Insert(0, Services.Localization.Localization.GetString("None.Text", Me.LocalResourceFile))
                Me.ddlFFG.Enabled = False
                Me.lkbAddFeature.Enabled = False
                Me.gvFeatures.Visible = False
                Me.lblFeatures.Text = Services.Localization.Localization.GetString("NoFGs.Text", Me.LocalResourceFile)
                Me.lblFeatures.Visible = True
            End If
        End If
    End Sub

    Protected Sub lbManageComparison_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lbManageComparison.Click
        Me.Response.Redirect(Me.EditUrl("ManageComparison"))
    End Sub

    Private Sub lbProductGroups_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lbProductGroups.Click
        Me.pnlProductFeatureText.Visible = False
        Me.pnlProductGroups.Visible = True
        Me.pnlProducts.Visible = False
        Me.pnlFeatureGroups.Visible = False
        Me.pnlFeatures.Visible = False
        Me.gvProductGroups.EditIndex = -1
        Me.gvProductGroups.Columns.Item(1).ItemStyle.Width = 15
        Me.rfvPG.Enabled = True
        Me.lkbSaveProductGroup.Enabled = True
        Me.BindProductGroups_Grid()
    End Sub

    Private Sub lbProducts_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lbProducts.Click
        Me.pnlProductFeatureText.Visible = False
        Me.pnlProducts.Visible = True
        Me.pnlProductGroups.Visible = False
        Me.pnlFeatureGroups.Visible = False
        Me.pnlFeatures.Visible = False
        Me.pnlSaveProduct.Visible = False
        Me.lkbAddProduct.Enabled = True
        Me.txtProduct.Text = String.Empty
        Me.txtPrice.Text = String.Empty
        Me.BindProductGroups_DDL()
        If (Me.ddlProductGroups.Items.Count > 0) Then
            Me.BindProducts_Grid()
        End If
    End Sub

    Private Sub lbProductFeatureText_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbProductFeatureText.Click
        Me.pnlProducts.Visible = False
        Me.pnlProductGroups.Visible = False
        Me.pnlFeatureGroups.Visible = False
        Me.pnlFeatures.Visible = False
        Me.pnlSaveProduct.Visible = False
        Me.pnlProductFeatureText.Visible = True
        Me.pnlPFT.Visible = False
        Me.txtPFText.Text = String.Empty
        Me.lkbAddPFText.Enabled = True
        Me.BindPFTPanel()
    End Sub

    Private Sub lkbAddFeature_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lkbAddFeature.Click
        Me.lblFeatures.Visible = False
        Me.gvFeatures.Visible = False
        Me.pnlSaveFeature.Visible = True
        Me.lkbAddFeature.Enabled = False
    End Sub

    Private Sub lkbAddFG_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lkbAddFG.Click
        Me.Page.Validate()
        If Me.Page.IsValid Then
            Dim fg As New FeatureGroupInfo
            Dim controller As New FeatureGroupController
            fg.FeatureGroupId = -1
            fg.FeatureGroup = Strings.Trim(Me.txtFeatureGroup.Text)
            fg.PortalId = Me.PortalId
            fg.SortOrder = -1
            fg.ProductGroupId = CInt(Me.ddlFGPG.SelectedValue)
            controller.SaveFeatureGroup(fg)
            Me.BindFeatureGroups_Grid()
            Me.txtFeatureGroup.Text = String.Empty
            controller = Nothing
            fg = Nothing
        End If
    End Sub

    Private Sub lkbAddProduct_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lkbAddProduct.Click
        Me.lblProduct.Visible = False
        Me.gvProducts.Visible = False
        Me.pnlSaveProduct.Visible = True
        Me.lkbAddProduct.Enabled = False
        Me.chbShowPrice.Checked = True
        Me.txtPrice.Enabled = True
    End Sub

    Private Sub lkbCancelFeature_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lkbCancelFeature.Click
        Me.txtComment.Text = String.Empty
        Me.txtFeature.Text = String.Empty
        Me.lkbAddFeature.Enabled = True
        Me.pnlSaveFeature.Visible = False
        Me.pnlFeatures.Visible = True
        If (Me.ddlFFG.Items.Count > 0) Then
            Me.BindFeatures_Grid()
        End If
    End Sub

    Private Sub lkbCancelProduct_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lkbCancelProduct.Click
        Me.pnlProducts.Visible = True
        Me.pnlSaveProduct.Visible = False
        Me.lkbAddProduct.Enabled = True
        Me.txtPFText.Text = String.Empty
        If (Me.ddlProductGroups.Items.Count > 0) Then
            Me.BindProducts_Grid()
        End If
    End Sub

    Private Sub lkbCancelPFT_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lkbCancelPFT.Click
        Me.pnlProductFeatureText.Visible = True
        Me.pnlPFT.Visible = False
        Me.lkbAddPFText.Enabled = True
        Me.txtProduct.Text = String.Empty
        Me.txtPrice.Text = String.Empty
        Me.BindPFTGrid()
    End Sub

    Private Sub lkbSaveFeature_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lkbSaveFeature.Click
        Me.Page.Validate()
        If Me.Page.IsValid Then
            Me.lkbAddFeature.Enabled = True
            Me.pnlFeatures.Visible = True
            Me.pnlSaveFeature.Visible = False
            Dim feature As New FeatureInfo
            Dim controller As New FeatureController
            If (Me.Session.Item("apc_FeatureId") Is Nothing) Then
                feature.Comment = Strings.Trim(Me.txtComment.Text)
                feature.Feature = Strings.Trim(Me.txtFeature.Text)
                feature.FeatureGroupId = CInt(Me.ddlFFG.SelectedValue)
                feature.FeatureId = -1
                feature.SortOrder = -1
                controller.SaveFeature(feature)
            Else
                feature = controller.GetFeature(CInt(Me.Session.Item("apc_FeatureId")))
                feature.Comment = Strings.Trim(Me.txtComment.Text)
                feature.Feature = Strings.Trim(Me.txtFeature.Text)
                feature.FeatureGroupId = CInt(Me.ddlFFG.SelectedValue)
                feature.FeatureId = CInt(Me.Session.Item("apc_FeatureId"))
                feature.SortOrder = feature.SortOrder
                controller.SaveFeature(feature)
                Me.gvFeatures.EditIndex = -1
                Me.Session.Item("apc_FeatureId") = Nothing
            End If
            Me.txtComment.Text = String.Empty
            Me.txtFeature.Text = String.Empty
            If (Me.ddlFFG.Items.Count > 0) Then
                Me.BindFeatures_Grid()
            End If
        End If
    End Sub

    Private Sub lkbSaveProduct_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lkbSaveProduct.Click
        Me.Page.Validate()
        If Me.Page.IsValid Then
            Me.lkbAddProduct.Enabled = True
            Me.pnlProducts.Visible = True
            Me.pnlSaveProduct.Visible = False
            Me.txtPrice.Enabled = True
            Dim prod As New ProductInfo
            Dim pc As New ProductController
            If Not (Me.Session.Item("apc_ProductId") Is Nothing) Then
                prod = pc.GetProduct(CInt(Me.Session.Item("apc_ProductId")))
                prod.DisplayPrice = Me.chbShowPrice.Checked
                prod.Price = CDec(Strings.Trim(Me.txtPrice.Text))
                prod.Product = Strings.Trim(Me.txtProduct.Text)
                Me.gvProducts.EditIndex = -1
                Me.Session.Item("apc_ProductId") = Nothing
            Else
                prod.Price = CDec(Strings.Trim(Me.txtPrice.Text))
                prod.DisplayPrice = Me.chbShowPrice.Checked
                prod.Product = Strings.Trim(Me.txtProduct.Text)
                prod.ProductGroupId = CInt(Me.ddlProductGroups.SelectedValue)
                prod.ProductId = -1
                prod.SortOrder = -1
            End If
            pc.SaveProduct(prod)
            Me.txtProduct.Text = String.Empty
            Me.txtPrice.Text = String.Empty
            If (Me.ddlProductGroups.Items.Count > 0) Then
                Me.BindProducts_Grid()
            End If
        End If
    End Sub

    Private Sub lkbSaveProductGroup_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lkbSaveProductGroup.Click
        Me.Page.Validate()
        If Me.Page.IsValid Then
            Dim pg As New ProductGroupInfo
            Dim controller As New ProductGroupController
            pg.ProductGroupId = -1
            pg.ProductGroup = Strings.Trim(Me.txtProductGroup.Text)
            pg.PortalId = Me.PortalId
            pg.ModuleId = Me.ModuleId
            pg.ProductGroupId = controller.SaveProductGroup(pg)
            Me.BindProductGroups_Grid()
            Me.txtProductGroup.Text = String.Empty
            controller = Nothing
            pg = Nothing
        End If
    End Sub

    Private Sub lkbSavePFT_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lkbSavePFT.Click
        Page.Validate()
        If Page.IsValid Then
            Dim pc As New ProductController
            pc.SaveProductNote(CInt(ddlPFTProducts.SelectedValue), CInt(Me.ddlPFTFeatures.SelectedValue), 5, Trim(Me.txtPFText.Text))
            pc = Nothing

            Me.pnlProducts.Visible = False
            Me.pnlProductGroups.Visible = False
            Me.pnlFeatureGroups.Visible = False
            Me.pnlFeatures.Visible = False
            Me.pnlSaveProduct.Visible = False
            Me.pnlProductFeatureText.Visible = True
            Me.pnlPFT.Visible = False
            Me.txtPFText.Text = String.Empty
            Me.lkbAddPFText.Enabled = True
            Me.BindPFTGrid()
        End If
    End Sub

    Public ReadOnly Property ModuleActions() As Entities.Modules.Actions.ModuleActionCollection Implements Entities.Modules.IActionable.ModuleActions
        Get
            Dim actions As New Actions.ModuleActionCollection
            actions.Add(Me.GetNextActionID, Services.Localization.Localization.GetString("ManageComparison.Text", Me.LocalResourceFile), "AddContent.Action", "", "", Me.EditUrl("ManageComparison"), False, DotNetNuke.Security.SecurityAccessLevel.Edit, True, False)
            Return actions
        End Get
    End Property

  
    Private _FeatureGroupSortOrder As Integer
    Private _FeatureSortOrder As Integer
    Private _ProductSortOrder As Integer

   


    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.lblComparisonSections.Text = Services.Localization.Localization.GetString("ComparisonSections.Text", Me.LocalResourceFile)
        Me.lkbAddFeature.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("AddFeatures.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/add2.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("AddFeatures.Text", Me.LocalResourceFile))
        Me.lkbAddFG.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("SaveFG.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/disk_blue.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("SaveFG.Text", Me.LocalResourceFile))
        Me.lkbAddPFText.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("AddPFT.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/add2.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("AddPFT.Text", Me.LocalResourceFile))
        Me.lkbAddProduct.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("AddProducts.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/add2.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("AddProducts.Text", Me.LocalResourceFile))
        Me.lkbCancelProduct.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("CancelProduct.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/undo.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("CancelProduct.Text", Me.LocalResourceFile))
        Me.lkbCancelFeature.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("CancelFeature.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/undo.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("CancelFeature.Text", Me.LocalResourceFile))
        Me.lkbSaveProductGroup.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("SavePG.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/disk_blue.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("SavePG.Text", Me.LocalResourceFile))
        Me.lkbSaveProduct.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("SaveProduct.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/disk_blue.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("SaveProduct.Text", Me.LocalResourceFile))
        Me.lkbSaveFeature.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("SaveFeature.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/disk_blue.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("SaveFeature.Text", Me.LocalResourceFile))
        Me.lkbSavePFT.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("SaveFeature.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/disk_blue.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("SaveFeature.Text", Me.LocalResourceFile))
        Me.lkbCancelPFT.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("CancelPFT.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/undo.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("CancelPFT.Text", Me.LocalResourceFile))
        Me.lbFeatureGroups.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("FeatureGroups.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/bookmarks.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("FeatureGroups.Text", Me.LocalResourceFile))
        Me.lbFeatures.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("Features.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/bookmark.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("Features.Text", Me.LocalResourceFile))
        Me.lbProductGroups.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("ProductGroups.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/gears.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("ProductGroups.Text", Me.LocalResourceFile))
        Me.lbProducts.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("Products.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/gear.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("Products.Text", Me.LocalResourceFile))
        Me.lbProductFeatureText.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("ProductFeatureText.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/gear.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("ProductFeatureText.Text", Me.LocalResourceFile))
        Me.lbManageComparison.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("ManageComparison.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/chart.gif") & """ border=""0"" /> " & Services.Localization.Localization.GetString("ManageComparison.Text", Me.LocalResourceFile))
        Me.rfvProduct.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("PNReq.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/warning.gif") & """ border=""0"" />")
        Me.rfvPrice.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("PPReq.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/warning.gif") & """ border=""0"" />")
        Me.cvPrice.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("PPFormat.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/warning.gif") & """ border=""0"" />")
        Me.rfvFeature.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("FNReq.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/warning.gif") & """ border=""0"" />")
        Me.rfvFG.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("FGReq.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/warning.gif") & """ border=""0"" />")
        Me.rfvPG.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("PGReq.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/warning.gif") & """ border=""0"" />")
        Me.rfvPFText.Text = ("<img hspace=""4"" alt=""" & Services.Localization.Localization.GetString("PFTReq.Text", Me.LocalResourceFile) & """ src=""" & Me.Page.ResolveUrl("~/DesktopModules/ActiveCompare/img/warning.gif") & """ border=""0"" />")

        Me.chbShowPrice.Attributes.Add("onclick", "javascipt:ac_displayPriceCheck(this.checked);")
        gvProductGroups.Columns(0).HeaderText = Services.Localization.Localization.GetString("ProductGroups.Text", Me.LocalResourceFile)
        gvProducts.Columns(0).HeaderText = Services.Localization.Localization.GetString("Products.Text", Me.LocalResourceFile)
        gvFeatureGroups.Columns(0).HeaderText = Services.Localization.Localization.GetString("FeatureGroups.Text", Me.LocalResourceFile)
        gvFeatures.Columns(0).HeaderText = Services.Localization.Localization.GetString("Features.Text", Me.LocalResourceFile)
        gvPFT.Columns(1).HeaderText = Services.Localization.Localization.GetString("ProductFeatureText.Text", Me.LocalResourceFile)

        If Not Me.IsPostBack Then
            Me.pnlProductGroups.Visible = True
            Me.pnlProducts.Visible = False
            Me.pnlFeatureGroups.Visible = False
            Me.pnlFeatures.Visible = False
            Me.pnlPFT.Visible = False
            Me.pnlProductFeatureText.Visible = False
            Me.BindProductGroups_Grid()
        End If
    End Sub

    Private Sub gvPFT_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gvPFT.RowCancelingEdit
        Me.gvPFT.EditIndex = -1
        Me.gvPFT.Columns.Item(4).ItemStyle.Width = 15
        Me.BindPFTGrid()        
        Me.lkbAddPFText.Enabled = True
    End Sub

    Private Sub gvPFT_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvPFT.RowDeleting
        Dim pi As Integer = CInt(Me.gvPFT.DataKeys.Item(e.RowIndex).Values().Item(0))
        Dim fi As Integer = CInt(Me.gvPFT.DataKeys.Item(e.RowIndex).Values().Item(1))
        Dim pc As New ProductController
        pc.DeleteProductNote(pi, fi)
        Me.gvPFT.EditIndex = -1
        Me.BindPFTGrid()
    End Sub

    Private Sub gvPFT_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvPFT.RowEditing
        Me.gvPFT.EditIndex = e.NewEditIndex
        Me.gvPFT.Columns.Item(4).ItemStyle.Width = 40
        Me.lkbAddPFText.Enabled = False
        Me.BindPFTGrid()
    End Sub

    Private Sub gvPFT_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvPFT.RowUpdating
        Dim box As TextBox = CType(Me.gvPFT.Rows.Item(e.RowIndex).Cells.Item(3).Controls.Item(0), TextBox)
        If New ProductController().SaveProductNote(CInt(Me.gvPFT.DataKeys.Item(e.RowIndex).Values().Item(0)), CInt(Me.gvPFT.DataKeys.Item(e.RowIndex).Values().Item(1)), 5, box.Text) Then
            Me.gvPFT.EditIndex = -1
            Me.gvPFT.Columns.Item(4).ItemStyle.Width = 15
            Me.lkbAddPFText.Enabled = True
            Me.BindPFTGrid()
        Else
            Me.gvPFT.EditIndex = -1
            Me.gvPFT.Columns.Item(4).ItemStyle.Width = 15
            Me.lkbAddPFText.Enabled = True
            Me.BindPFTGrid()
        End If
    End Sub

    Private Sub lkbAddPFText_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lkbAddPFText.Click
        Me.ddlPFTFGs.Visible = True
        Me.ddlPFTPGs.Visible = True
        Me.lkbAddPFText.Enabled = False
        Me.gvPFT.Visible = False
        Me.lblPFTMessage.Visible = False
        Me.pnlPFT.Visible = True
        lblPFTProductGroups.Visible = True
        lblPFTFeatureGroups.Visible = True

        Me.ddlPFTProducts.DataSource = New ProductController().GetProductListByProductGroupId(CInt(Me.ddlPFTPGs.SelectedValue))
        Me.ddlPFTProducts.DataValueField = "ProductId"
        Me.ddlPFTProducts.DataTextField = "Product"
        Me.ddlPFTProducts.DataBind()
        Me.ddlPFTProducts.Enabled = True

        Me.ddlPFTFeatures.DataSource = New FeatureController().GetFeatures(CInt(Me.ddlPFTFGs.SelectedValue))
        Me.ddlPFTFeatures.DataValueField = "FeatureId"
        Me.ddlPFTFeatures.DataTextField = "Feature"
        Me.ddlPFTFeatures.DataBind()
        Me.ddlPFTFeatures.Enabled = True

        If (Me.ddlPFTProducts.Items.Count <= 0) Then
            Me.ddlPFTProducts.Items.Insert(0, Services.Localization.Localization.GetString("None.Text", Me.LocalResourceFile))
            Me.ddlPFTProducts.Items.Item(0).Value = "0"
            Me.ddlPFTProducts.Enabled = False

            Me.lkbSavePFT.Enabled = False
            Me.lblPFTMessage.Visible = False
        End If
        If (Me.ddlPFTFeatures.Items.Count <= 0) Then
            Me.ddlPFTFeatures.Items.Insert(0, Services.Localization.Localization.GetString("None.Text", Me.LocalResourceFile))
            Me.ddlPFTFeatures.Items.Item(0).Value = "0"
            Me.ddlPFTFeatures.Enabled = False

            Me.lkbSavePFT.Enabled = False
            Me.lblPFTMessage.Visible = False
        End If

    End Sub

    Private Sub ddlPFTFGs_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPFTFGs.SelectedIndexChanged
        If Me.pnlPFT.Visible Then
            Me.lkbSavePFT.Enabled = True
            Me.lkbAddPFText.Enabled = False
            Me.ddlPFTFeatures.DataSource = New FeatureController().GetFeatures(CInt(ddlPFTFGs.SelectedValue))
            Me.ddlPFTFeatures.DataTextField = "Feature"
            Me.ddlPFTFeatures.DataValueField = "FeatureId"
            Me.ddlPFTFeatures.DataBind()
            Me.ddlPFTFeatures.Enabled = True

            If ddlPFTFeatures.Items.Count <= 0 Then
                Me.ddlPFTFeatures.Items.Insert(0, Services.Localization.Localization.GetString("None.Text", Me.LocalResourceFile))
                Me.ddlPFTFeatures.Items.Item(0).Value = "0"
                Me.ddlPFTFeatures.Enabled = False
                Me.lkbSavePFT.Enabled = False
            End If
        Else
            Me.gvPFT.EditIndex = -1
            Me.BindPFTGrid()
        End If
    End Sub

    Private Sub ddlPFTPGs_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPFTPGs.SelectedIndexChanged
        Me.ddlPFTFGs.DataSource = New FeatureGroupController().GetFeatureGroupsByProductGroupId(CInt(ddlPFTPGs.SelectedValue))
        Me.ddlPFTFGs.DataValueField = "FeatureGroupId"
        Me.ddlPFTFGs.DataTextField = "FeatureGroup"
        Me.ddlPFTFGs.DataBind()
        Me.ddlPFTFGs.Enabled = True

        Me.lkbSavePFT.Enabled = True
        Me.lkbAddPFText.Enabled = True

        If Me.pnlPFT.Visible Then
            Me.lkbSavePFT.Enabled = True
            Me.lkbAddPFText.Enabled = False

            Me.ddlPFTProducts.DataSource = New ProductController().GetProductListByProductGroupId(CInt(Me.ddlPFTPGs.SelectedValue))
            Me.ddlPFTProducts.DataValueField = "ProductId"
            Me.ddlPFTProducts.DataTextField = "Product"
            Me.ddlPFTProducts.DataBind()
            Me.ddlPFTProducts.Enabled = True

            If (Me.ddlPFTProducts.Items.Count <= 0) Then
                Me.ddlPFTProducts.Items.Insert(0, Services.Localization.Localization.GetString("None.Text", Me.LocalResourceFile))
                Me.ddlPFTProducts.Items.Item(0).Value = "0"
                Me.ddlPFTProducts.Enabled = False

                Me.lkbSavePFT.Enabled = False
                Me.lblPFTMessage.Visible = False            
            End If

            If (Me.ddlPFTFGs.Items.Count <= 0) Then
                Me.ddlPFTFGs.Items.Insert(0, Services.Localization.Localization.GetString("None.Text", Me.LocalResourceFile))
                Me.ddlPFTFGs.Items.Item(0).Value = "0"
                Me.ddlPFTFGs.Enabled = False

                Me.ddlPFTFeatures.DataSource = New FeatureController().GetFeatures(CInt(ddlPFTFGs.SelectedValue))
                Me.ddlPFTFeatures.DataTextField = "Feature"
                Me.ddlPFTFeatures.DataValueField = "FeatureId"
                Me.ddlPFTFeatures.DataBind()
                Me.ddlPFTFeatures.Enabled = True

                If ddlPFTFeatures.Items.Count <= 0 Then
                    Me.ddlPFTFeatures.Items.Insert(0, Services.Localization.Localization.GetString("None.Text", Me.LocalResourceFile))
                    Me.ddlPFTFeatures.Items.Item(0).Value = "0"
                    Me.ddlPFTFeatures.Enabled = False
                    Me.lkbSavePFT.Enabled = False
                End If
            End If
        Else
            If (Me.ddlPFTFGs.Items.Count <= 0) Then
                Me.ddlPFTFGs.Items.Insert(0, Services.Localization.Localization.GetString("None.Text", Me.LocalResourceFile))
                Me.ddlPFTFGs.Items.Item(0).Value = "0"
                Me.ddlPFTFGs.Enabled = False

                Me.gvPFT.Visible = False
                Me.lblPFTMessage.Visible = True
            Else
                Me.gvPFT.EditIndex = -1
                Me.BindPFTGrid()
            End If

        End If
    End Sub
End Class


